package edu.gatech.cc.CFAWaffleFriesWheresMyStuff.common;

import java.util.Date;

/**
 * An information holding class representing a single item within the system. TBD: implement location, date, and images.
 * @author Michael Luke Hawkins
 */
public class Item {
	protected Integer ID;
	protected String creatorName;
	protected String name;
	protected String description;
	protected boolean open;
	protected Category category;
	protected Type type;
	protected String location;
	protected Date date;
	protected double reward;
	
	/**
	 * An enum to hold all possible Item types
	 *
	 */
	public enum Type{
		Lost("Lost"),
		Found("Found"),
		Donation("Donation"),
		DonationRequest("DonationRequest");
		
		String _val;
		Type(String val)
		{
			_val = val;
		}
		/**
		 * Parses the given string into a Type enum member.
		 * @param val The string value to parse. Must be non-null. Should be one of the following:
		 * 	Lost, Found, Donation, or DonationRequest
		 * @return An instance of Type corresponding to val.
		 */
		public static Type parse(String val)
		{
			if(val.equals("Lost")) {
				return Lost;
			}
			if(val.equals("Found")) {
				return Found;
			}
			if(val.equals("Donation")) {
				return Donation;
			}
			if(val.equals("DonationRequest")) {
				return DonationRequest;
			}
			return Lost;
		}
		public String toString()
		{
			return _val;
		}
	}
	
	/**
	 * An enum to hold all possible Item categories
	 *
	 */
	public enum Category{
		Keepsake("Keepsake"),
		Heirloom("Heirloom"),
		Miscellaneous("Miscellaneous");
		
		String _val;
		Category(String val)
		{
			_val = val;
		}
		/**
		 * Parses the given string into a Category enum member.
		 * @param val The string value to parse. Must be non-null. Should be one of the following:
		 * 	Keepsake, Heirloom, Miscellaneous
		 * @return An instance of Category corresponding to val.
		 */
		public static Category parse(String val)
		{
			if(val.equals("Keepsake")) {
				return Keepsake;
			}
			if(val.equals("Heirloom")) {
				return Heirloom;
			}
			if(val.equals("Miscellaneous")) {
				return Miscellaneous;
			}
			return Miscellaneous;
		}
		public String toString()
		{
			return _val;
		}
	}
	
	/**
	 * Constructs a new Item with the given information
	 * @param username The username of this item's creator
	 * @param name The name of the item
	 * @param description The description of the item
	 * @param isOpen The open/close status of the item
	 * @param category The category of the item
	 * @param type The type of the item
	 * @param location The location of the item
	 * @param date The date the item was created
	 * @param reward The reward value for this item.
	 */
	public Item(int ID, String username, String name, String description, boolean isOpen, Category category, Type type, String location, long date, double reward){
		this.ID = ID;
		this.creatorName=username;
		this.name=name;
		this.description=description;
		this.open = isOpen;
		this.category = category;
		this.type = type;
		this.location=location;
		
		this.date = new Date(date);
		
		this.reward = reward;
	}
	
	
	/**
	 * Returns the name of this item.
	 * @return Item name
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * Returns the name of the User who created this item.
	 * @return the creatorName
	 */
	public String getCreatorName() {
		return creatorName;
	}

	/**
	 * Sets the name of the User who created this item.
	 * @param creatorName the creatorName to set
	 */
	public void setCreatorName(String creatorName) {
		this.creatorName = creatorName;
	}

	/**
	 * Returns the description of this item.
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * Sets the description of this item.
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * Returns the open/closed status of this item.
	 * @return the open/closed status of this item.
	 */
	public boolean isOpen() {
		return open;
	}

	/**
	 * Sets the open/closed status of this item.
	 * @param open the open to set
	 */
	public void setOpen(boolean open) {
		this.open = open;
	}

	/**
	 * Returns the category of this item.
	 * @return the category of this item
	 */
	public Category getCategory() {
		return category;
	}

	/**
	 * Sets the category of this item.
	 * @param category the category to set
	 */
	public void setCategory(Category category) {
		this.category = category;
	}

	/**
	 * Returns the type of this item.
	 * @return the type
	 */
	public Type getType() {
		return type;
	}

	/**
	 * Sets the type of this item.
	 * @param type the type to set
	 */
	public void setType(Type type) {
		this.type = type;
	}

	/**
	 * Returns the location of this item.
	 * @return the location
	 */
	public String getLocation() {
		return location;
	}

	/**
	 * Sets the location of this item.
	 * @param location the location to set
	 */
	public void setLocation(String location) {
		this.location = location;
	}

	/**
	 * Returns the date on which this item was posted to the system.
	 * @return the date
	 */
	public Date getDate() {
		return date;
	}

	/**
	 * Sets the date on which this item was posted to the system.
	 * @param date the date to set
	 */
	public void setDate(Date date) {
		this.date = date;
	}

	/**
	 * Returns the award associated with this item.
	 * @return the reward
	 */
	public double getReward() {
		return reward;
	}

	/**
	 * Sets the reward associated with this item.
	 * @param reward the reward to set
	 */
	public void setReward(double reward) {
		this.reward = reward;
	}

	/**
	 * Sets the name of this item.
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Returns the ID of this item.
	 * @return the iD
	 */
	public Integer getID() {
		return ID;
	}
	
}
